package com.hmall.trade.config;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;

/**
 * @author Administrator
 * @version 1.0
 * @description: TODO
 * @date 2025/6/17 17:19
 */
@Data
@NoArgsConstructor
@AllArgsConstructor(staticName = "of")
public class DelayMessagePostProcessor implements MessagePostProcessor {
    private String type;
    private Long delayTime;

    @Override
    public Message postProcessMessage(Message message) throws AmqpException {
        if ("dlx".equals(type)) {
            message.getMessageProperties().setExpiration(String.valueOf(delayTime));
        } else if ("delay".equals(type)) {
            message.getMessageProperties().setDelay(delayTime.intValue());
        }
        return message;
    }
}
